package com.world.cat.service.sys;

import com.world.cat.enums.FileType;
import com.world.cat.service.sys.BaseService;
import com.world.common.pojo.Result;
import com.world.common.util.SysUtil;
import com.world.core.dao.GenericRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

import com.world.cat.dao.sys.UploadRelationDao;
import com.world.cat.model.sys.UploadRelation;

@Service
@Transactional
public class UploadRelationService extends BaseService<UploadRelation> {
    @Resource
    private UploadRelationDao uploadRelationdao;

    @Override
    public GenericRepository getDao() {
        return uploadRelationdao;
    }

    public Result save(FileType fileType, String objId, String fileId) {
        if (SysUtil.isEmpty(objId)) {
            return new Result(false, "对象ID为空");
        }
        if (SysUtil.isEmpty(fileId)) {
            return new Result(false, "文件ID为空");
        }

        UploadRelation uploadRelation = new UploadRelation();
        uploadRelation.setFileType(fileType);
        uploadRelation.setObjId(objId);
        uploadRelation.setFileId(fileId);
        uploadRelationdao.save(uploadRelation);

        return new Result(true, "保存成功");
    }
}
